const app = getApp();
const axios = require('../../utils/axios');

Page({
  data: {
    id: null,
    user: app.globalData.user,
    data: {}
  },

  onLoad(options) {
    const id = Number(options.id);
    this.setData({ id });
    this.getData();
  },

  getData() {
    const header = app.globalData.header;
    const { id } = this.data;
    axios.get('/staff/' + id, {}, header).then(res => {
      var { code, data, err } = res;
      console.log(res);
      if(code == 200) {
        data.educationHistory = JSON.parse(data.educationHistory);
        data.workHistory = JSON.parse(data.workHistory);
        data.projectHistory = JSON.parse(data.projectHistory);
        data.awardHistory = JSON.parse(data.awardHistory);
        console.log(data);
        this.setData({ data });
      } else if (code == 401) {
        app.login(() => this.getData());
      } else throw err;
    }).catch(err => {
      wx.showModal({
        title: '错误',
        content: JSON.stringify(err),
        showCancel: false
      });
    });
  },
})